import Vue from 'vue'
import VueRouter from 'vue-router'

import Login from "@/pages/Login"
import Home from "@/pages/home/index"
import DoublePrevent from "@/pages/doublePrevent/index"
import SafeStand from "@/pages/safeStand/index"
import safeTarget from "@/pages/safeTarget/index"
import hisEvent from "@/pages/hisEvent/index"
import carryEvent from "@/pages/carryEvent/index"
import compDanger from "@/pages/compDanger/index"
import carryDanger from "@/pages/carryDanger/index"
import yearTarget from "@/pages/yearTarget/index"
import board from "@/pages/board/index"
import newCompSafe from "@/pages/newCompSafe/index"

import emergencyPlan from "@/pages/emergencyPlan/index"
import knowShare from "@/pages/knowShare/index"



/* eslint-disable */
Vue.use(VueRouter)

const router = new VueRouter({
	mode: "hash",
	base: process.env.BASE_URL,
	routes: [{
		path: "/",
		redirect: "/user/login",
		// redirect: "/home/board"
	},
	{
		path: "/user",
		component: () => import('@/layout/SimpleLayout.vue'),
		meta: {
			title: '用户',
		},
		children: [
			{
				path: "login",
				component: () => import('@/pages/login/index.vue'),
				name: "login",
				meta: {
					title: '用户登录'
				},
			}]
	},

	{
		path: "/config",
		component: () => import('@/layout/ConfigLayout.vue'),
		meta: {
			title: '配置',
		},
		children: [

			{
				path: "/config/board",
				component: () => import('@/pages/config/board/index.vue'),
				name: "configBoard",
				meta: {
					title: '工作台'
				},
			},

			{
				path: "/config/carry-danger",
				component: () => import('@/pages/config/carryDanger/index.vue'),
				name: "compDangerStat",
				meta: {
					title: '隐患统计'
				},
			},



			{
				path: "/config/company-risk",
				component: () => import('@/pages/config/companyRisk/index.vue'),
				name: "companyRisk",
				meta: {
					title: '隐患提交'
				},
			},

			{
				path: "/config/company-risk-detail/:riskId",
				component: () => import('@/pages/config/companyRiskDetail/index.vue'),
				name: "companyRiskDetail",
				meta: {
					title: '隐患查看'
				},
			},


			{
				path: "/config/risk-table",
				component: () => import('@/pages/config/riskTable/index.vue'),
				name: "riskTable",
				meta: {
					title: '隐患数据'
				},
			},






		]
	},


	]
})

router.beforeEach((to, from, next) => {
	console.log('name', to.name)
	if (to.name === 'login') {
		next();
		return;
	}
	// next();
	const userStr = sessionStorage.getItem('user');
	if (userStr) {
		const user = JSON.parse(userStr);
		if (user) {
			next();
			return
		}
	}
	next({
		name: "login"
	});

});


export default router